package ex.tableapi.join;

import ex.tableapi.ApiFrame;
import org.apache.flink.table.api.Table;

import static org.apache.flink.table.api.Expressions.$;

public class ExOuterJoin extends ApiFrame {
    private String outName = "printOutTable";

    public static void main(String[] args) {
        ExOuterJoin demo = new ExOuterJoin();
        demo.getEnv();
        Table orders = demo.registerMysql("myorder", "orders");

        Table result = demo.exOuterJoin(orders);

        demo.registerConsole(demo.createPrintOutDDL(result.getResolvedSchema().toString()), demo.outName);
        result.executeInsert(demo.outName);
    }

    private Table exOuterJoin(Table orders) {
        Table left = orders.select($("a"), $("b"), $("c"));
        Table right = orders.select($("d"), $("e"), $("f"));

//        Table leftOuterResult = left.leftOuterJoin(right, $("a").isEqual($("d")))
//                .select($("a"), $("b"), $("e"));
        Table rightOuterResult = left.rightOuterJoin(right, $("a").isEqual($("d")))
                .select($("a"), $("b"), $("e"));
        Table fullOuterResult = left.fullOuterJoin(right, $("a").isEqual($("d")))
                .select($("a"), $("b"), $("e"));
        return fullOuterResult;
    }



}
